package com.situation.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situation.mapper.BizProductMapper;
import com.situation.pojo.DO.BizProduct;
import com.situation.pojo.VO.ProductStocksVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @description:
 * @author: 羽程
 * @create: 2021-12-07 19:49
 **/
@Service
public class BizProductServiceImpl {
    @Autowired
    BizProductMapper bizProductMapper;

    /**
     * 添加物资信息
     * @param bizProduct
     * @return
     */
    public int insertProduct(BizProduct bizProduct){
        bizProduct.setCreateTime(LocalDateTime.now());
        bizProduct.setModifiedTime(LocalDateTime.now());
        return bizProductMapper.insert(bizProduct);
    }

    /**
     * 从回收站回收物资，回收完为审核状态
     * @param bizProduct
     * @return
     */
    public int back(BizProduct bizProduct){
        bizProduct.setStatus(2);
        return bizProductMapper.updateStatus(bizProduct);
    }

    /**
     *将物资放入回收站
     * @param bizProduct
     * @return
     */
    public int remove(BizProduct bizProduct){
        bizProduct.setStatus(0);
        return bizProductMapper.updateStatus(bizProduct);
    }

    /**
     * 删除物资
     * @param bizProduct
     * @return
     */
    public int delete(BizProduct bizProduct){
        return bizProductMapper.delete(bizProduct);
    }

    /**
     * 更新物资信息
     */
    public int update(BizProduct bizProduct){
        return bizProductMapper.updateProduct(bizProduct);
    }

    /**
     * 通过ID查询物资信息
     * @param bizProduct
     * @return
     */
    public BizProduct findBizProductById(BizProduct bizProduct){
        return bizProductMapper.findBizProductById(bizProduct);
    }

    /**
     * 查询所有物资库存信息
     * @return
     */
    public PageInfo<ProductStocksVO> findAllStocks(BizProduct bizProduct,int pageNum,int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<ProductStocksVO> allStocks = bizProductMapper.findAllStocks(bizProduct);
        PageInfo<ProductStocksVO> pageInfo = new PageInfo<>(allStocks);
        return pageInfo;
    }

    /**
     * 多条件+通过名称模糊查询
     * @return
     */
    public PageInfo<BizProduct> findProductList(BizProduct bizProduct, int pageNum, int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<BizProduct> list = bizProductMapper.findProductList(bizProduct);
        PageInfo<BizProduct> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

}
